package com.Ajava1704.for设计模式.for责任链模式过滤器;

import java.util.Vector;

/**
 * 作者: LCG
 * 日期: 2020/2/15 09:13
 * 描述:
 */
public class ForFilterChainImpl implements ForFilterChain {

    private Vector<ForFilter> vector=new Vector<>();

    public void register(ForFilter forFilter){
        vector.add(forFilter);
    }

    public void register(int order,ForFilter forFilter){
        vector.add(order,forFilter);
    }

    private int index=0;

    @Override
    public void chain() {

         if(index<vector.size()){
             ForFilter forFilter = vector.get(index);
             index++;
             forFilter.doFilter(this);
         }

    }
}
